package org.test.client.ui.content.table.bstable;

import java.awt.Color;
import java.awt.Dimension;
import java.util.Comparator;

import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;

import org.test.client.ui.util.Icons;

public class BsTable extends JTable{
	
	BootStrapTableRender cellRender = null;
	int bsRowHeight = 30;
	Color borderColor = new Color(Integer.parseInt("dddddd",16));
	
	public BsTable(){
		doInit();
	}
	
	public void doInit(){
		
		cellRender = new BootStrapTableRender();
		this.setRowHeight(20);
		this.setIntercellSpacing(new Dimension(0,1));
		this.setGridColor(borderColor);
		this.setShowVerticalLines(false);
		
		JTableHeader tableHeader = this.getTableHeader();
//		tableHeader.setReorderingAllowed(false);
		tableHeader.setDefaultRenderer(cellRender);
	}
	
	@Override
	public void setModel(TableModel tablemodel) {
		super.setModel(tablemodel);
		
		TableColumnModel columnModel = this.getColumnModel();
		int count = columnModel.getColumnCount();
		for(int i=0;i<count;i++){
			TableColumn column = columnModel.getColumn(i);
			column.setCellRenderer(cellRender);
		}
		bsRowHeight = 38;
		this.setRowHeight(bsRowHeight);

	}
	
	@Override
	public void setShowVerticalLines(boolean flag) {
		super.setShowVerticalLines(flag);
		if(cellRender != null){
			cellRender.setNeedVerticalLine(flag);
		}
	}
}

/**
 * 按数字排序 升序
 * @author Guodeqi
 *
 */
class OrderNumberComparator implements Comparator{

    public int compare(Object o1, Object o2) {
        try {
			int i = Integer.parseInt(o1.toString().trim()) - Integer.parseInt(o2.toString().trim());
		    return i;
		} catch (Exception e) {
			return ((Comparable)o1).compareTo(o2);
		}
    }
}


